from sklearn.externals import joblib
import numpy as np

# 线性回归预测模型
def liner_load_and_predict(sex, part, data):
  # 添加性别特征
  if sex == 'female':
    data.append(1)
  else:
    data.append(0)

  part_error = {
    'chest': 65,
    'waist': 40,
    'hips': 50
  }

  mm_path = 'static/data_file/grid_model/mm_liner' + '_' + part + '.pkl'
  model_path = 'static/data_file/grid_model/liner' + '_' + part + '.pkl'

  mm = joblib.load(mm_path)
  model = joblib.load(model_path)
  input_data = mm.transform([data])
  predict = np.array(model.predict(input_data)) + part_error[part]

  return int(predict[0])

if __name__ == '__main__':
  print(liner_load_and_predict('male', 'chest', [[300, 200]]))